
const rob = function (nums) {
  const len = nums.length
  if (len === 0) return 0;
  if (len === 1) return nums[0]
  if (len === 2) return Math.max(...nums)
  const dp = []
  dp[0] = nums[0]
  dp[1] = Math.max(nums[0], nums[1])
  for (let i = 2; i < len; i++) {
    dp[i] = Math.max((nums[i] + dp[i - 2]), dp[i - 1])
  }
  return dp[dp.length - 1]
};

const testArr = [1, 3, 3, 1, 2, 4, 5, 6, 7, 8, 9, 10]
console.log(rob(testArr));


// *动态规划
// 偷钱最多的算法   --动态规划   子项问题相互依赖影响


